<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="goods.*"%>
<%@ page import="java.util.*"%>
<%@ page import="cart.*"%>
<%@ page import="java.net.URLEncoder" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ include file="/Dmyna/head.jsp"%>

<%
String gs_code = request.getParameter("GS_CODE");
GoodsManager manager = GoodsManager.getInstance();
GoodsItem writing = manager.select(gs_code);

StringTokenizer optionColor = new StringTokenizer(writing.getColor_code(), "|");
StringTokenizer optionSize = new StringTokenizer(writing.getSize_code(), "|");
String optionTmp = "";

%>


<script type="text/javascript">
function validate(){
	if(orderForm.LIST_GS_COUNT.value == ""){
		alert("수량을 선택하세요");
		return false;
	}
	else if(orderForm.LIST_GS_SIZE.value == ""){
		alert("사이즈를 선택하세요");
		return false;
	}
	else if(orderForm.LIST_GS_COLOR.value == ""){
		alert("색상을 선택하세요");
		return false;
	}

	document.orderForm.submit();
}

function addCart(){
	if(orderForm.LIST_GS_COUNT.value == ""){
		alert("수량을 선택하세요");
		return false;
	}
	else if(orderForm.LIST_GS_SIZE.value == ""){
		alert("사이즈를 선택하세요");
		return false;
	}
	else if(orderForm.LIST_GS_COLOR.value == ""){
		alert("색상을 선택하세요");
		return false;
	}

	document.addCartForm.GS_CNT.value = document.orderForm.LIST_GS_COUNT.value;
	document.addCartForm.GS_COLOR.value = document.orderForm.LIST_GS_COLOR.value;
	document.addCartForm.GS_SIZE.value = document.orderForm.LIST_GS_SIZE.value;

	code = document.addCartForm.GS_CODE.value;
	cnt = document.addCartForm.GS_CNT.value;
	color = document.addCartForm.GS_COLOR.value;
	size = document.addCartForm.GS_SIZE.value;

	openUrl = "/goodsToCart?GS_CODE="+code+"&GS_CNT="+cnt+"&GS_COLOR="+color+"&GS_SIZE="+size;
	//openUrl = "/Dmyna/test.jsp?GS_CODE="+code+"&GS_CNT="+cnt+"&GS_COLOR="+color+"&GS_SIZE="+size;
	openWin = "cart_result";
	openOpt = "width=350,height=300"; 

	newWin = window.open(openUrl,openWin,openOpt);
	newWin.focus();

	//document.addCartForm.submit();




}
</script>

<c:set var="writing" value="<%=writing%>" />

<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;" align="center">
					::&nbsp;&nbsp;${writing.gs_name }&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<br />
<br />
<c:if test="${empty writing }">
존재하지 않는 상품입니다.
</c:if>

<c:if test="${!empty writing }">

<form action="${WEB_ROOT}/order/orderForm.jsp" name="orderForm" method="post" onSubmit="return validate()">
<input type="hidden"  name="LIST_GS_CODE" value="${writing.gs_code }">
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<%--
	<tr align="right">
	<td width="200" align="right" width="50%">
		조&nbsp; 회&nbsp; 수 :
		${writing.gs_view_cnt }
	</td>
</tr>
--%>
<tr>
	<td>
		<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
		<!-- 제품 상세 내용 : 상단 -->
		<tr align="center">
			<td align="center" width="45%">
				<img src="${WEB_ROOT }/goods/upload/${writing.gs_img }" width="190" />
			</td>
			<!-- 상단 가격 내용 -->
			<td align="center" width="50%">
				<table border="0" height="1" width="100%" cellpadding="0" cellspacing="0">
				<col width="55" />
				<col width="115" />
				<col  />
				<col width="1" />
				<tr>
					<td height="35"></td>
					<td align="right">
						상&nbsp;
						&nbsp;품&nbsp; &nbsp;명 :
					</td>
					<td align="center">${writing.gs_name }</td>
					<td ></td>
				</tr>
				<tr>
					<td height="35"></td>
					<td align="right">판&nbsp; &nbsp;매&nbsp; &nbsp;가 :</td>
					<c:choose>
					<c:when test="${writing.gs_org_price == writing.gs_sale_price }">
						<td align="center"><fmt:formatNumber value="${writing.gs_org_price }" type="number"/> 원</td>
					</c:when>
					<c:otherwise>
						<td align="center"><strike><fmt:formatNumber value="${writing.gs_org_price }" type="number"/> 원</strike></td>
					</c:otherwise>
					</c:choose>
					<td></td>
				</tr>
				<c:choose>
					<c:when test="${writing.gs_org_price == writing.gs_sale_price }">
					<td></td>
					<td></td>
					<td></td>
					</c:when>
					<c:otherwise>
				<tr>
					<td height="35"></td>
					<td align="right">
						<font color="red">할&nbsp;
						&nbsp;인&nbsp; &nbsp;가 :</font></td>
						<td align="center"><font color="red"><b><fmt:formatNumber value="${writing.gs_sale_price }" type="number"/> 원</b></font></td>
					<td></td>
				</tr>
				</c:otherwise>
				</c:choose>
				<tr>
					<td height="35"></td>
					<td align="right">수&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;량 :</td>
					<td align="center">
						<select name="LIST_GS_COUNT">
						<option value="">선택하세요</option>
						<option value="1">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
						<option value="5">5</option>
						</select>
					</td>
					<td></td>
				</tr>
				<tr>
					<td height="35"></td>
					<td align="right">사&nbsp; &nbsp;이&nbsp; &nbsp;즈 :</td>
					<td align="center">
						<select name="LIST_GS_SIZE">
						<option value="">선택하세요</option>
						<%
						while (optionSize.hasMoreTokens()) {
						optionTmp = optionSize.nextToken();
						%>
						<option value="<%=optionTmp%>"><%=optionTmp%></option>
						<%
						}
						%>
						</select>
					</td>
					<td></td>
				</tr>
				<tr>
					<td height="35"></td>
					<td align="right">색&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;상 :</td>
					<td align="center">
						<select name="LIST_GS_COLOR">
						<option value="">선택하세요</option>
						<%
						while (optionColor.hasMoreTokens()) {
						optionTmp = optionColor.nextToken();
						%>
						<option value="<%=optionTmp%>"><%=optionTmp%></option>
						<%
						}
						%>
						</select>
					</td>
					<td></td>
				</tr>
				<tr>
					<td align="center" colspan="4" height="50">
					<br />
<c:if test="${sessionScope.SESSION_MB_NO != null }">
<table height="111" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td width="121">
		<a href="#" onclick="javascript:validate()">
		<img src='${WEB_ROOT }/img/goods/buy.gif' onmouseover="this.src='${WEB_ROOT }/img/goods/buy_on.gif';" onmouseout="this.src='${WEB_ROOT }/img/goods/buy.gif';" alt="" />
		</a>
	</td>
	<td width="136">
		<a href="#" onclick="javascript:addCart()" >
		<img src='${WEB_ROOT }/img/goods/cart.gif' onmouseover="this.src='${WEB_ROOT }/img/goods/cart_on.gif';" onmouseout="this.src='${WEB_ROOT }/img/goods/cart.gif';" alt=""  />
		</a>
	</td>
	<td width="106">
		<a href="javascript:win_open('/wishInsert.do?GS_CODE=${writing.gs_code }&MB_NO=${sessionScope.SESSION_MB_NO }', 'wishwin', 'scrollbars=yes,width=350,height=300,top=10,left=20')">
		<img src='${WEB_ROOT }/img/goods/wish.gif' onmouseover="this.src='${WEB_ROOT }/img/goods/wish_on.gif';" onmouseout="this.src='${WEB_ROOT }/img/goods/wish.gif';" alt=""  />
		</a>
	</td>
</tr>
</table>
</c:if>
					</td>
				</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="4" height="50">
				<!-- 공백 -->
			</td>
		</tr>
		<!-- 제품 상세 내용 : 메인-->
		<tr align="center">
			<td colspan="2" class="topline">
				<br>
				<c:if test="${writing.gs_img2 !=null }">
				<img src="${WEB_ROOT }/goods/upload/${writing.gs_img2 }" onload="if(this.width<900){this.width=this.width} else if(this.width>=900){this.width=900}"  /><br /> <br /> <br />
				</c:if>
			</td>
		</tr>
		<tr>
			<td colspan="2" class="topline" align="left">
				<br />${writing.gs_content }<br />
			</td>
		</tr>
		</table>
	</td>
</tr>
</table>
</form>



<table width="900" border="0" align="center">
<!-- 제품 상세 내용 : 문의 게시판 -->
<tr align="center">
	<td colspan="2" height="250" class="topline">
		<p>
		<%@ include file="/Dmyna/qna/goodsQnaList.jsp"%>
		<p>
	</td>
</tr>
<!-- 제품 상세 내용 : 리뷰 게시판 -->
<tr align="center">
	<td colspan="2" height="250" class="topline">
		<p>
		<%@ include file="/Dmyna/review/goodsReviewList.jsp"%>
		<p>
	</td>
</tr>
<tr>
	<td colspan="2" class="topline" height="50">
		<!-- 공백 -->
	</td>
</tr>
</table>

</c:if>

<form name="addCartForm" method="post" >
<input type="hidden" name="GS_CODE" value="${writing.gs_code }">
<input type="hidden" name="GS_CNT" value="">
<input type="hidden" name="GS_COLOR" value="">
<input type="hidden" name="GS_SIZE" value="">
</form>


<%

	//최근본 상품 쿠키에 저장하기

	//쿠키는 한글은 저장이 안되므로 한글로 저장하려면 인코딩 지정 해야함

	Cookie cookie=new Cookie("item",URLEncoder.encode("${writing.gs_img2 }","utf-8"));

	cookie.setMaxAge(60*2);//2분 쿠키 유지시간 지정

	response.addCookie(cookie);
	//System.out.println("cookie: "+cookie);

%>


<%@ include file="/Dmyna/tail.jsp"%>
